$(document).ready(function()
{
	$(".wrapper").hover(
	        function(){
	            $(".box").show();
	        }, function() {
	            //if (!$(".box").is(":hover"))
	                $(".box").hide();
	        }
	    );

	Carrito.Cargar();
	//TestRest.Cargar();
	
});

function AjaxCall(url, data, responsediv, onsuccess){

    var control = null;
       
    if (responsediv != null){
        control = '#' + responsediv;
    }
    
    $.ajax({
        type: 'POST',
        url: url,
        data: data,
        dataType: 'html',
        cache: false,
        beforeSend : function(){
            if (control != null){
                SetBusyStatus(control, true, true);
            }
        },
        success : function(result){
            if (control != null){
                $(control).html(result);
            }
            if (onsuccess != null){
                onsuccess();
            }
        },
        error : function(XMLHttpRequest, textStatus, errorThrown){
            alert(textStatus + ': ' + (errorThrown || XMLHttpRequest.status + ' - ' + XMLHttpRequest.statusText) + '\nUrl: ' + this.url);
        },
        complete: function(XMLHttpRequest, textStatus){
            if (control != null){
                SetBusyStatus(control, false, true);
            }
        }
    });
}

function SetContextBusyStatus(fromelm, context, bool, noBusy ){
	var planElm = $(fromelm).closest(context);
	if(planElm){
        if(noBusy !== true){
		    SetBusyStatus( fromelm, bool, false);
		}
		SetBusyStatus( planElm, bool, true );
	}
}

function SetBusyStatus(elm, bool, doblock ){
    //http://jquery.malsup.com/block/
    if (elm.substring(1,0)!='#'){
        elm = '#'+elm;
    }
    
	if(bool){
        $(elm).addClass('busy');
		if(doblock){
			$(elm).block({ message: null });
        }
	}else{
		$(elm).removeClass('busy');
		if(doblock){
			$(elm).unblock();
        }
	}	
}